#include "Keyboard.h"

bool Keyboard::keyCurrent[256];
bool Keyboard::keySwitch[256];
bool Keyboard::keyWasReleased[256];
bool Keyboard::keyPrevious[256];

bool Keyboard::KeyPressed(unsigned int number)
{
	return keyCurrent[number];
}

bool Keyboard::KeyPreviouslyPressed(unsigned int number)
{
	return keyPrevious[number];
}

bool Keyboard::NewKeyPressed(unsigned int number) {
	return keyCurrent[number] && !keyPrevious[number];
}

void Keyboard::SetKeyPressed(unsigned int number)
{
	keyCurrent[number] = true;
	if(keyWasReleased[number])
	{
		keyWasReleased[number] = false;
		keySwitch[number] = !keySwitch[number];
	}
}

void Keyboard::SetKeyReleased(unsigned int number)
{
	keyCurrent[number] = false;
	keyWasReleased[number] = true;
}

bool Keyboard::KeySwitch(unsigned int number)
{
	return keySwitch[number];
}

void Keyboard::Reset(void)
{
	int i;
	for(i = 0; i < 256; i++)
	{
		Keyboard::keyCurrent[i] = false;
		Keyboard::keySwitch[i] = false;
		Keyboard::keyWasReleased[i] = true;
		Keyboard::keyPrevious[i] = false;
	}
}

void Keyboard::Update(void)
{
	int i;
	for(i = 0; i < 256; i++)
	{
		Keyboard::keyPrevious[i] = Keyboard::keyCurrent[i];
	}
}
